<template>
  <pro-layout
    :title="title"
    :menus="menus"
    :collapsed="collapsed"
    :mediaQuery="query"
    :isMobile="isMobile"
    :handleMediaQuery="handleMediaQuery"
    :handleCollapse="handleCollapse"
    :logo="logoRender"
    v-bind="settings"
  >
   <template v-slot:menuHeaderRender>
      <div class="pro-layout-title">
          <span v-show="!collapsed" class="title">数据中台</span>
          <span class="collapse">
            <a-icon v-show="!collapsed" @click="handleCollapse(true)" type="menu-fold" />
            <a-icon v-show="collapsed" @click="handleCollapse(false)" type="menu-unfold" />
          </span>
        <!-- <img class="logo" src="@/modules/common/imgs/logo.png"> -->
      </div>
    </template>
    <!-- :i18nRender="i18nRender" -->
    <template #headerContentRender>
      <!-- <HeadOper></HeadOper> -->
      <ZkMultiTabs :settings="settings" :isMobile="isMobile"></ZkMultiTabs>
      <right-content :top-menu="settings.layout === 'topmenu'" :is-mobile="isMobile" :theme="settings.theme" />
    </template>
    <!-- <setting-drawer :settings="settings" @change="handleSettingChange" /> -->
    <!-- <template v-slot:rightContentRender>
      <right-content :top-menu="settings.layout === 'topmenu'" :is-mobile="isMobile" :theme="settings.theme" />
    </template> -->
    <template v-slot:footerRender>
      <global-footer />
    </template>
    <router-view/>
  </pro-layout>
</template>

<script>

import { PageHeaderWrapper } from '@ant-design-vue/pro-layout'
// import { i18nRender } from '@/locales'
import { mapState } from 'vuex'
// import { SIDEBAR_TYPE, TOGGLE_MOBILE_TYPE } from '@/store/mutation-types'
import defaultSettings from '@/config/defaultSettings'
import RightContent from '@/components/GlobalHeader/RightContent'
import GlobalFooter from '@/components/GlobalFooter'
// import LogoSvg from '@/assets/logo.png?inline'
import ZkMultiTabs from '@/appBase/ZkMultiTabs.vue'
import HeadOper from '@/modules/common/components/HeadOper.vue'
// import RouteView from './RouteView.vue'

export default {
  name: 'BasicLayout',
  components: {
    // SettingDrawer,
    RightContent,
    GlobalFooter,
    PageHeaderWrapper,
    ZkMultiTabs,
    HeadOper
    // RouteView
  },
  data () {
    return {
      // preview.pro.antdv.com only use.
      isProPreviewSite: process.env.VUE_APP_PREVIEW === 'true' && process.env.NODE_ENV !== 'development',
      // end

      // base
      menus: [],
      // 侧栏收起状态
      collapsed: false,
      // title: defaultSettings.title,
      settings: {
        // 布局类型
        layout: defaultSettings.layout, // 'sidemenu', 'topmenu'
        // 定宽: true / 流式: false
        contentWidth:'Fluid'|| defaultSettings.layout === 'sidemenu' ? 'Fluid' : defaultSettings.contentWidth === 'Fixed',
        // 主题 'dark' | 'light'
        theme: defaultSettings.navTheme,
        // 主色调
        primaryColor: defaultSettings.primaryColor,
        fixedHeader: defaultSettings.fixedHeader,
        fixSiderbar: defaultSettings.fixSiderbar,
        colorWeak: defaultSettings.colorWeak,

        hideHintAlert: false,
        hideCopyButton: false
      },
      // 媒体查询
      query: {},

      // 是否手机模式
      isMobile: false
    }
  },
  computed: {
    ...mapState({
      // 动态主路由
      mainMenu: state => state.dynamicRouter,
      title: state=>state.nowUserInfo.name||defaultSettings.title
    })
  },
  created () {
    const routes = this.mainMenu.find(item => item.path === '/')
    this.menus = (routes && routes.children) || []
    // 处理侧栏收起状态
    // this.$watch('collapsed', () => {
    //   this.$store.commit(SIDEBAR_TYPE, this.collapsed)
    // })
    // this.$watch('isMobile', () => {
    //   this.$store.commit(TOGGLE_MOBILE_TYPE, this.isMobile)
    // })
  },
  mounted () {
    const userAgent = navigator.userAgent
    if (userAgent.indexOf('Edge') > -1) {
      this.$nextTick(() => {
        this.collapsed = !this.collapsed
        setTimeout(() => {
          this.collapsed = !this.collapsed
        }, 16)
      })
    }

    // first update color
    // TIPS: THEME COLOR HANDLER!! PLEASE CHECK THAT!!
    if (process.env.NODE_ENV !== 'production' || process.env.VUE_APP_PREVIEW === 'true') {
      // updateTheme(this.settings.primaryColor)
    }
  },
  methods: {
    // i18nRender,
    handleMediaQuery (val) {
      this.query = val
      if (this.isMobile && !val['screen-xs']) {
        this.isMobile = false
        return
      }
      if (!this.isMobile && val['screen-xs']) {
        this.isMobile = true
        this.collapsed = false
        this.settings.contentWidth = false
        // this.settings.fixSiderbar = false
      }
    },
    handleCollapse (val) {
      this.collapsed = val
    },
    handleSettingChange ({ type, value }) {
      console.log('type', type, value)
      type && (this.settings[type] = value)
      switch (type) {
        case 'contentWidth':
          this.settings[type] = value === 'Fixed'
          break
        case 'layout':
          if (value === 'sidemenu') {
            this.settings.contentWidth = false
          } else {
            this.settings.fixSiderbar = false
            this.settings.contentWidth = true
          }
          break
      }
    },
    logoRender () {
      // <LogoSvg />
      return <span></span>
    }
  }
}
</script>

<style lang="less">
@import "./BasicLayout.less";
.pro-layout-title{
  margin-left: -24px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  .title {
    font-size: 20px;
    line-height: 1.5;
    font-weight: bold;
    color: #fff;
    margin-right: 20px;
  }
  i {
    font-size: 20px;
    color: #fff;
  }
   & > h1{
     margin-left: 0;
     display: inline-block;
   }
}
.ant-pro-global-header-trigger {
  display: none;
}
.ant-pro-sider-menu-logo svg {
  width: inherit;
  height: inherit;
}
</style>
